
package com.dy.config;

import lombok.Data;

/**
 * @Description:
 * @Date：2018年6月28日 @author： DongY
 * @version ：1.0 1.[2018年6月28日]CreatBy：dy
 */
@Data
public class MysqlConfig {
	public static final String MYSQL = "mysql";
	public static final String SQL_SERVER = "sqlserver";
	public static final String ORCAL = "orcal";
	public static final String MYSQL_DRIVER_DEFAULT = "com.mysql.jdbc.Driver";
	public static final String DEFAULT_USER = "root";
	public static final String DEFAULT_PASSWORD = "123456";
	public static final String DEFAULT_URL = "jdbc:mysql://192.168.0.118:3306/model_number_db?useUnicode=true&characterEncoding=utf-8";

	private String dbType = MYSQL;
	private String user = DEFAULT_USER;
	private String password = DEFAULT_PASSWORD;
	private String driver = MYSQL_DRIVER_DEFAULT;
	private String url = DEFAULT_URL;
	private String dbName;

	public void initDbName(final String url) {
		String dbString = "";
		if (url.indexOf('?') > 0) {
			dbString = url.substring(0, url.indexOf('?'));
		}
		dbString = dbString.substring(dbString.lastIndexOf("/") + 1);// 如果是\斜杠再次判断处理，目前暂时不考虑
		dbName = dbString;
	}

	public void setUrl(final String url) {
		this.url = url;
		initDbName(url);
		System.out.println(this);
	}
}
